<template>
  <div class="video">
    <div class="topbox">
      <div class="iconBox" @click.stop="showsidebar">
        <i class="iconfont icon-hanbaocaidan"></i>
      </div>
      <div class="title">
        <div class="find">
          <i class="iconfont icon-sousuo"></i>
          <span>华晨宇&nbsp;《好想我回来啊》</span>
        </div>
        <input type="text" />
      </div>
    </div>
    <van-list class="contentbox" v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <div class="videominbox" v-for="(ele,index) in videolist" :key="index" @click.stop="showvideo(ele.data.vid)">
        <div class="imgbox">
          <img class="videoimg" :src="ele.data.coverUrl" alt />
          <div class="faceimg" v-if="ele.data.creator">
            <img class="facearcimg" :src="ele.data.creator.avatarUrl" alt />
          </div>
          <div class="duration">{{ele.data.durationms|time}}</div>
        </div>
        <div class="titlebox van-ellipsis">{{ele.data.title}}</div>
        <div class="detailbox">
          <div class="left">
            <i class="iconfont icon-24gl-play"></i>
            {{ele.data.playTime|playcount}}
          </div>
          <div class="center">
            <i class="iconfont icon-dianzan"></i>
            {{ele.data.praisedCount|playcount}}
          </div>
          <div class="right" v-if="ele.data.videoGroup">{{ele.data.videoGroup[0].name}}</div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { getVideoRecommend } from "../assets/api/video.js";
export default {
  data() {
    return {
      videolist: [],
      offset: 0,
      loading: false,
      finished: false,
    };
  },
  methods: {
    showvideo(vid) {
      this.$emit("showvideoson", vid);
    },
    onLoad() {
      console.log(this.offset);
      getVideoRecommend({ offset: this.offset }).then((data) => {
        data.datas = data.datas.filter((e) => e.data.coverUrl);
        this.videolist.push(...data.datas);
        this.loading = false;
      });
      this.offset += 1;
    },
  },

  filters: {
    playcount(v) {
      return v > 10000 ? (v / 10000).toFixed(1) + "万" : v;
    },
    time(v) {
      let m = parseInt(v / 1000 / 60);
      m = m < 10 ? "0" + m : m;
      let s = parseInt(v / 1000 - 60 * m);
      s = s < 10 ? "0" + s : s;
      return m + ":" + s;
    },
  },
  created() {
    this.onLoad();
  },
};
</script>

<style lang="less">
.video {
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 124px);
  position: fixed;
  overflow: scroll;
  padding: 0;
  .topbox {
    height: 60px;
    backdrop-filter: blur(15px);
    background-color: rgba(255, 255, 255, 0.01);
    background-blend-mode: multiply;
    line-height: 60px;
    display: flex;
    color: white;
    align-items: center;
    padding: 16px 16px;
    box-sizing: border-box;
    .iconBox {
      flex: 0 0 24px;
      padding: 0;
      margin: 0;
      i {
        top: 2px;
        position: relative;
        font-size: 24px;
      }
    }
    .title {
      flex: 1;
      text-align: center;
      margin-left: 22px;
      position: relative;
      .find {
        margin: auto;
        position: absolute;
        left: 0;
        right: 0;
        color: rgba(255, 255, 255, 0.2);
        i {
          margin-right: 8px;
        }
      }
      input {
        box-sizing: border-box;
        width: 100%;
        height: 30px !important;
        line-height: 30px;
        padding: 0 26px;
        background: none;
        border: none;
        background-color: rgba(255, 255, 255, 0.1);
        border-radius: 1000px;
      }
    }
  }
  .contentbox {
    display: flex;
    flex-wrap: wrap;
    padding: 0 16px;
    justify-content: space-between;
    .videominbox {
      width: 48%;
      background-color: rgba(255, 255, 255, 0.1);
      border-radius: 8px;
      height: 287px;
      overflow: hidden;
      margin-top: 8px;
      &:nth-child(2n + 1) {
        margin-right: 8px;
      }
      .imgbox {
        position: relative;
        width: 100%;
        height: 220px;
        .faceimg {
          width: 26px;
          height: 26px;
          border-radius: 50%;
          overflow: hidden;
          position: absolute;
          left: 8px;
          bottom: 8px;
          .facearcimg {
            width: 100%;
          }
        }
        .videoimg {
          position: absolute;
          margin: auto;
          top: 0;
          left: -50%;
          right: 0;
          height: 220px;
        }
        .duration {
          position: absolute;
          color: rgba(255, 255, 255, 0.8);
          bottom: 8px;
          right: 8px;
        }
      }
      .titlebox {
        font-size: 14px;
        padding: 0 12px 0 10px;
        margin-top: 10px;
        color: rgba(255, 255, 255, 0.9);
      }
      .detailbox {
        height: 14px;
        line-height: 14px;
        font-size: 12px;
        padding: 0 12px 0 10px;
        margin-top: 12px;
        display: flex;
        color: rgba(255, 255, 255, 0.5);
        align-items: center;
        .right {
          text-align: right;
        }
        .center {
          flex: 1;
        }
        i {
          font-size: 12px;
        }
      }
    }
  }
}
</style>